home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-06-12 | 25.8 KB | 922 lines | [TEXT/KAHL] |
- ///--------------------------------------------------------------------------------------
- // SpriteWorld.c
- //
- // Created: Wednesday, May 29, 1991 at 10:43:28 PM
- // By: Tony Myles
- //
- // Copyright: © 1991-93 Tony Myles, All rights reserved worldwide.
- //
- // Description: implementation of the sprite world architecture
- ///--------------------------------------------------------------------------------------
-
-
- #ifndef __QUICKDRAW__
- #include <QuickDraw.h>
- #endif
-
- #ifndef __MEMORY__
- #include <Memory.h>
- #endif
-
- #ifndef __GESTALTEQU__
- #include <GestaltEqu.h>
- #endif
-
- #ifndef __SPRITEWORLDUTILS__
- #include <SpriteWorldUtils.h>
- #endif
-
- #ifndef __SPRITEWORLD__
- #include <SpriteWorld.h>
- #endif
-
- #ifndef __SPRITELAYER__
- #include <SpriteLayer.h>
- #endif
-
- #ifndef __SPRITE__
- #include <Sprite.h>
- #endif
-
- #ifndef __FRAME__
- #include <Frame.h>
- #endif
-
-
- ///--------------------------------------------------------------------------------------
- // SWEnterSpriteWorld
- ///--------------------------------------------------------------------------------------
-
- SW_PASCAL OSErr SWEnterSpriteWorld(void)
- {
- OSErr err;
- long versionNumber;
-
- // make sure we can run in this environment
- err = Gestalt(gestaltTimeMgrVersion, &versionNumber);
-
- if ((err != noErr) || (versionNumber < gestaltStandardTimeMgr))
- {
- err = kTimeMgrNotPresentErr;
- }
-
- return err;
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWExitSpriteWorld
- ///--------------------------------------------------------------------------------------
-
- SW_PASCAL void SWExitSpriteWorld(void)
- {
- // nothing happens here right now, but that might change later
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWCreateSpriteWorld
- ///--------------------------------------------------------------------------------------
-
- SW_PASCAL OSErr SWCreateSpriteWorld(
- SpriteWorldPtr *spriteWorldP,
- FramePtr windowFrameP,
- FramePtr backFrameP,
- FramePtr loadFrameP)
- {
- OSErr err;
- CGrafPtr curGrafP;
- GDHandle curGDeviceH;
- FramePtr tempFrameP;
- SpriteWorldPtr tempSpriteWorldP;
-
- err = noErr;
- *spriteWorldP = NULL;
-
- tempSpriteWorldP = (SpriteWorldPtr)NewPtrClear((Size)sizeof(SpriteWorldRec));
-
- if (tempSpriteWorldP != NULL)
- {
- tempSpriteWorldP->windowFrameP = windowFrameP;
- tempSpriteWorldP->backFrameP = backFrameP;
- tempSpriteWorldP->loadFrameP = loadFrameP;
- tempSpriteWorldP->eraseDrawProc = SWStdDrawProc;
- tempSpriteWorldP->screenDrawProc = SWStdMaskDrawProc;
-
- *spriteWorldP = tempSpriteWorldP;
- }
- else
- {
- err = MemError();
- }
-
- return err;
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWCreateSpriteWorldFromWindow
- ///--------------------------------------------------------------------------------------
-
- SW_PASCAL OSErr SWCreateSpriteWorldFromWindow(
- SpriteWorldPtr* spriteWorldP,
- CWindowPtr srcWindowP,
- Rect* worldRect)
- {
- OSErr err;
- CGrafPtr savePort;
- GDHandle saveGDevice;
- FramePtr windowFrameP, backFrameP, loadFrameP;
- Rect tempRect;
-
- *spriteWorldP = NULL;
- windowFrameP = backFrameP = loadFrameP = NULL;
-
- tempRect = (worldRect == NULL) ? srcWindowP->portRect : *worldRect;
-
- GetPort((GrafPtr*)&savePort);
- SetPort((GrafPtr)srcWindowP);
-
- // create window frame
- err = SWCreateFrame(&windowFrameP, srcWindowP, &tempRect);
-
- if (err == noErr)
- {
- // create back drop frame
- err = SWCreateFrame(&backFrameP, NULL, &tempRect);
- }
-
- if (err == noErr)
- {
- // create loader frame
- err = SWCreateFrame(&loadFrameP, NULL, &tempRect);
- }
-
- if (err == noErr)
- {
- // create sprite world
- err = SWCreateSpriteWorld(spriteWorldP, windowFrameP, backFrameP, loadFrameP);
- }
-
- if (err != noErr)
- {
- // an error occurred so dispose of anything we managed to create
-
- if (windowFrameP != NULL)
- {
- SWDisposeFrame(windowFrameP);
- }
-
- if (backFrameP != NULL)
- {
- SWDisposeFrame(backFrameP);
- }
-
- if (loadFrameP != NULL)
- {
- SWDisposeFrame(loadFrameP);
- }
- }
-
- SetPort((GrafPtr)savePort);
-
- return err;
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWDisposeSpriteWorld
- ///--------------------------------------------------------------------------------------
-
- SW_PASCAL void SWDisposeSpriteWorld(
- SpriteWorldPtr spriteWorldP)
- {
- if (spriteWorldP != NULL)
- {
- SWDisposeFrame(spriteWorldP->backFrameP);
-
- SWDisposeFrame(spriteWorldP->loadFrameP);
-
- spriteWorldP->windowFrameP->framePort.colorGrafP = NULL;
- SWDisposeFrame(spriteWorldP->windowFrameP);
-
- DisposePtr((Ptr)spriteWorldP);
- }
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWAddSpriteLayer
- ///--------------------------------------------------------------------------------------
-
- SW_PASCAL void SWAddSpriteLayer(
- SpriteWorldPtr spriteWorldP,
- SpriteLayerPtr newSpriteLayerP)
- {
- SpriteLayerPtr tailSpriteLayerP = spriteWorldP->tailSpriteLayerP;
-
- if (tailSpriteLayerP != NULL)
- {
- // doubly link the new layer
- tailSpriteLayerP->nextSpriteLayerP = newSpriteLayerP;
- newSpriteLayerP->prevSpriteLayerP = tailSpriteLayerP;
- newSpriteLayerP->nextSpriteLayerP = NULL;
- }
- else
- {
- newSpriteLayerP->prevSpriteLayerP = NULL;
- newSpriteLayerP->nextSpriteLayerP = NULL;
-
- // make the new layer the head
- spriteWorldP->headSpriteLayerP = newSpriteLayerP;
- }
-
- // make the new layer the tail
- spriteWorldP->tailSpriteLayerP = newSpriteLayerP;
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWRemoveSpriteLayer
- ///--------------------------------------------------------------------------------------
-
- SW_PASCAL void SWRemoveSpriteLayer(
- SpriteWorldPtr spriteWorldP,
- SpriteLayerPtr oldSpriteLayerP)
- {
- // is there a next layer?
- if (oldSpriteLayerP->nextSpriteLayerP != NULL)
- {
- // link the next layer to the prev layer
- oldSpriteLayerP->nextSpriteLayerP->prevSpriteLayerP = oldSpriteLayerP->prevSpriteLayerP;
- }
- else
- {
- // make the prev layer the tail
- spriteWorldP->tailSpriteLayerP = oldSpriteLayerP->prevSpriteLayerP;
- }
-
- // is there a prev layer?
- if (oldSpriteLayerP->prevSpriteLayerP != NULL)
- {
- // link the prev layer to the next layer
- oldSpriteLayerP->prevSpriteLayerP->nextSpriteLayerP = oldSpriteLayerP->nextSpriteLayerP;
- }
- else
- {
- // make the next layer the head
- spriteWorldP->headSpriteLayerP = oldSpriteLayerP->nextSpriteLayerP;
- }
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWSwapSpriteLayer
- ///--------------------------------------------------------------------------------------
-
- SW_PASCAL void SWSwapSpriteLayer(
- SpriteWorldPtr spriteWorldP,
- SpriteLayerPtr srcSpriteLayerP,
- SpriteLayerPtr dstSpriteLayerP)
- {
- register SpriteLayerPtr swapSpriteLayerP;
-
- swapSpriteLayerP = srcSpriteLayerP->nextSpriteLayerP;
- srcSpriteLayerP->nextSpriteLayerP = dstSpriteLayerP->nextSpriteLayerP;
- dstSpriteLayerP->nextSpriteLayerP = swapSpriteLayerP;
-
- swapSpriteLayerP = srcSpriteLayerP->prevSpriteLayerP;
- srcSpriteLayerP->prevSpriteLayerP = dstSpriteLayerP->prevSpriteLayerP;
- dstSpriteLayerP->prevSpriteLayerP = swapSpriteLayerP;
-
- if (srcSpriteLayerP->nextSpriteLayerP == NULL)
- {
- spriteWorldP->tailSpriteLayerP = srcSpriteLayerP;
- }
- else if (srcSpriteLayerP->prevSpriteLayerP == NULL)
- {
- spriteWorldP->headSpriteLayerP = srcSpriteLayerP;
- }
-
- if (dstSpriteLayerP->nextSpriteLayerP == NULL)
- {
- spriteWorldP->tailSpriteLayerP = dstSpriteLayerP;
- }
- else if (dstSpriteLayerP->prevSpriteLayerP == NULL)
- {
- spriteWorldP->headSpriteLayerP = dstSpriteLayerP;
- }
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWGetNextSpriteLayer
- ///--------------------------------------------------------------------------------------
-
- SW_PASCAL SpriteLayerPtr SWGetNextSpriteLayer(
- SpriteWorldPtr spriteWorldP,
- SpriteLayerPtr curSpriteLayerP)
- {
- return (curSpriteLayerP == NULL) ?
- spriteWorldP->headSpriteLayerP :
- curSpriteLayerP->nextSpriteLayerP;
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWLockSpriteWorld
- ///--------------------------------------------------------------------------------------
-
- SW_PASCAL void SWLockSpriteWorld(
- SpriteWorldPtr spriteWorldP)
- {
- SpriteLayerPtr curSpriteLayerP;
-
- SWLockFrame(spriteWorldP->windowFrameP);
- SWLockFrame(spriteWorldP->backFrameP);
- SWLockFrame(spriteWorldP->loadFrameP);
-
- curSpriteLayerP = spriteWorldP->headSpriteLayerP;
-
- while (curSpriteLayerP != NULL)
- {
- SWLockSpriteLayer(curSpriteLayerP);
-
- curSpriteLayerP = curSpriteLayerP->nextSpriteLayerP;
- }
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWUnlockSpriteWorld
- ///--------------------------------------------------------------------------------------
-
- SW_PASCAL void SWUnlockSpriteWorld(
- SpriteWorldPtr spriteWorldP)
- {
- SpriteLayerPtr curSpriteLayerP;
-
- SWUnlockFrame(spriteWorldP->windowFrameP);
- SWUnlockFrame(spriteWorldP->backFrameP);
- SWUnlockFrame(spriteWorldP->loadFrameP);
-
- curSpriteLayerP = spriteWorldP->headSpriteLayerP;
-
- while (curSpriteLayerP != NULL)
- {
- SWUnlockSpriteLayer(curSpriteLayerP);
-
- curSpriteLayerP = curSpriteLayerP->nextSpriteLayerP;
- }
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWSetPortToBackGround
- ///--------------------------------------------------------------------------------------
-
- SW_PASCAL void SWSetPortToBackGround(
- SpriteWorldPtr spriteWorldP)
- {
- SetPort(spriteWorldP->backFrameP->framePort.monoGrafP);
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWSetPortToWindow
- ///--------------------------------------------------------------------------------------
-
- SW_PASCAL void SWSetPortToWindow(
- SpriteWorldPtr spriteWorldP)
- {
- SetPort(spriteWorldP->windowFrameP->framePort.monoGrafP);
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWSetSpriteWorldEraseProc
- ///--------------------------------------------------------------------------------------
-
- SW_PASCAL void SWSetSpriteWorldEraseProc(
- SpriteWorldPtr spriteWorldP,
- DrawProcPtr eraseProc)
- {
- spriteWorldP->eraseDrawProc = eraseProc;
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWSetSpriteWorldDrawProc
- ///--------------------------------------------------------------------------------------
-
- SW_PASCAL void SWSetSpriteWorldDrawProc(
- SpriteWorldPtr spriteWorldP,
- MaskDrawProcPtr drawProc)
- {
- spriteWorldP->screenDrawProc = drawProc;
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWUpdateSpriteWorld
- ///--------------------------------------------------------------------------------------
-
- SW_PASCAL void SWUpdateSpriteWorld(
- SpriteWorldPtr spriteWorldP)
- {
- register SpriteLayerPtr curSpriteLayerP;
- register SpritePtr curSpriteP;
- Rect rgnRect;
-
- // the current port should the one in which we are drawing
- SetPort(spriteWorldP->loadFrameP->framePort.monoGrafP);
-
- (*spriteWorldP->eraseDrawProc)(spriteWorldP->backFrameP,
- spriteWorldP->loadFrameP,
- &spriteWorldP->loadFrameP->frameRect,
- &spriteWorldP->loadFrameP->frameRect);
-
- curSpriteLayerP = spriteWorldP->headSpriteLayerP;
-
- // iterate through the layers in this world
- while (curSpriteLayerP != NULL)
- {
- curSpriteP = curSpriteLayerP->headSpriteP;
-
- // iterate through the sprites in this layer
- while (curSpriteP != NULL)
- {
- if (curSpriteP->isVisible)
- {
- if (curSpriteP->curFrameP->maskRgn != NULL)
- {
- rgnRect = (**curSpriteP->curFrameP->maskRgn).rgnBBox;
-
- // move the mask region to the new sprite location
- OffsetRgn(curSpriteP->curFrameP->maskRgn,
- (curSpriteP->destFrameRect.left - rgnRect.left) +
- curSpriteP->curFrameP->offsetPoint.h,
- (curSpriteP->destFrameRect.top - rgnRect.top) +
- curSpriteP->curFrameP->offsetPoint.v);
- }
-
- // copy the sprite image onto the back drop piece
- (*curSpriteP->frameDrawProc)(curSpriteP->curFrameP,
- spriteWorldP->loadFrameP,
- &curSpriteP->curFrameP->frameRect,
- &curSpriteP->destFrameRect);
- }
-
- curSpriteP = curSpriteP->nextSpriteP;
- }
-
- curSpriteLayerP = curSpriteLayerP->nextSpriteLayerP;
- }
-
- // the current port should the one in which we are drawing
- SetPort(spriteWorldP->windowFrameP->framePort.monoGrafP);
-
- (*spriteWorldP->screenDrawProc)(spriteWorldP->loadFrameP,
- spriteWorldP->windowFrameP,
- &spriteWorldP->windowFrameP->frameRect,
- &spriteWorldP->windowFrameP->frameRect,
- NULL);
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWProcessSpriteWorld
- ///--------------------------------------------------------------------------------------
-
- SW_PASCAL void SWProcessSpriteWorld(
- SpriteWorldPtr spriteWorldP)
- {
- register SpriteLayerPtr curSpriteLayerP;
- SpriteLayerPtr nextSpriteLayerP;
- register SpritePtr curSpriteP;
- SpritePtr nextSpriteP;
- register FramePtr oldFrameP, newFrameP;
- Rect rgnRect;
- Point spritePoint, oldPoint;
- short horizOffset, vertOffset;
-
- curSpriteLayerP = spriteWorldP->headSpriteLayerP;
-
- // iterate through the layers in this world
- while (curSpriteLayerP != NULL)
- {
- nextSpriteLayerP = curSpriteLayerP->nextSpriteLayerP;
- curSpriteP = curSpriteLayerP->headSpriteP;
-
- // iterate through the sprites in this layer
- while (curSpriteP != NULL)
- {
- nextSpriteP = curSpriteP->nextSpriteP;
-
- // is it time to advance the sprite’s frame?
- if (curSpriteP->frameTimeTask.hasTaskFired)
- {
- register short horizFrameDelta;
- register short vertFrameDelta;
-
- if (curSpriteP->frameAdvance < 0)
- {
- // is this the first frame?
- if (curSpriteP->curFrameIndex <= curSpriteP->firstFrameIndex)
- {
- // wrap to the last frame
- curSpriteP->curFrameIndex = curSpriteP->lastFrameIndex;
- }
- else
- {
- // advance to next frame
- curSpriteP->curFrameIndex += curSpriteP->frameAdvance;
- }
- }
- else if (curSpriteP->frameAdvance > 0)
- {
- // is this the last frame?
- if (curSpriteP->curFrameIndex >= curSpriteP->lastFrameIndex)
- {
- // wrap to the first frame
- curSpriteP->curFrameIndex = curSpriteP->firstFrameIndex;
- }
- else
- {
- // advance to next frame
- curSpriteP->curFrameIndex += curSpriteP->frameAdvance;
- }
- }
-
- // get new frame
- newFrameP = curSpriteP->frameArray[curSpriteP->curFrameIndex];
-
- // is there a frame callback?
- if (curSpriteP->frameChangeProc != NULL)
- {
- // call it
- (*curSpriteP->frameChangeProc)(curSpriteP, newFrameP,
- &curSpriteP->curFrameIndex);
-
- // make sure the new frame index is in range
- if (curSpriteP->curFrameIndex < 0)
- {
- curSpriteP->curFrameIndex = 0;
- }
- else if (curSpriteP->curFrameIndex >= curSpriteP->maxFrames)
- {
- curSpriteP->curFrameIndex = curSpriteP->maxFrames - 1;
- }
- }
-
- // change the frame
- newFrameP = curSpriteP->frameArray[curSpriteP->curFrameIndex];
-
- // has the frame actually changed?
- if (curSpriteP->curFrameP != newFrameP)
- {
- oldFrameP = curSpriteP->curFrameP;
- curSpriteP->curFrameP = newFrameP;
-
- horizOffset = (curSpriteP->destFrameRect.left - newFrameP->frameRect.left);
- vertOffset = (curSpriteP->destFrameRect.top - newFrameP->frameRect.top);
-
- curSpriteP->destFrameRect = newFrameP->frameRect;
-
- curSpriteP->destFrameRect.left += horizOffset;
- curSpriteP->destFrameRect.right += horizOffset;
- curSpriteP->destFrameRect.top += vertOffset;
- curSpriteP->destFrameRect.bottom += vertOffset;
-
- curSpriteP->needsToBeDrawn = true;
- }
-
- if (curSpriteP->frameTimeInterval > 0)
- {
- curSpriteP->frameTimeTask.hasTaskFired = false;
-
- // reset the time till next frame
- PrimeTime((QElemPtr)&curSpriteP->frameTimeTask, curSpriteP->frameTimeInterval);
- }
- }
-
- // is it time to move the sprite?
- if (curSpriteP->moveTimeTask.hasTaskFired)
- {
- // is there a movement callback?
- if (curSpriteP->spriteMoveProc != NULL)
- {
- oldPoint = spritePoint;
-
- spritePoint.h = curSpriteP->destFrameRect.left + curSpriteP->horizMoveDelta;
- spritePoint.v = curSpriteP->destFrameRect.top + curSpriteP->vertMoveDelta;
-
- // call it
- (*curSpriteP->spriteMoveProc)(curSpriteP, &spritePoint);
-
- if ((spritePoint.h != oldPoint.h) || (spritePoint.v != oldPoint.v))
- {
- curSpriteP->destFrameRect.right = (curSpriteP->destFrameRect.right -
- curSpriteP->destFrameRect.left) +
- spritePoint.h;
- curSpriteP->destFrameRect.bottom = (curSpriteP->destFrameRect.bottom -
- curSpriteP->destFrameRect.top) +
- spritePoint.v;
- curSpriteP->destFrameRect.left = spritePoint.h;
- curSpriteP->destFrameRect.top = spritePoint.v;
-
- curSpriteP->needsToBeDrawn = true;
- }
- }
- else if ((curSpriteP->horizMoveDelta != 0) || (curSpriteP->vertMoveDelta != 0))
- {
- // offset destination rect (way faster than OffsetRect)
- curSpriteP->destFrameRect.top += curSpriteP->vertMoveDelta;
- curSpriteP->destFrameRect.left += curSpriteP->horizMoveDelta;
- curSpriteP->destFrameRect.bottom += curSpriteP->vertMoveDelta;
- curSpriteP->destFrameRect.right += curSpriteP->horizMoveDelta;
-
- curSpriteP->needsToBeDrawn = true;
- }
-
- if (curSpriteP->moveTimeInterval > 0)
- {
- curSpriteP->moveTimeTask.hasTaskFired = false;
-
- // reset the time till next move
- PrimeTime((QElemPtr)&curSpriteP->moveTimeTask,
- curSpriteP->moveTimeInterval);
- }
- }
-
- if (nextSpriteP != NULL)
- {
- curSpriteP = nextSpriteP;
- }
- else
- {
- curSpriteP = curSpriteP->nextSpriteP;
- }
- }
-
- if (nextSpriteLayerP != NULL)
- {
- curSpriteLayerP = nextSpriteLayerP;
- }
- else
- {
- curSpriteLayerP = curSpriteLayerP->nextSpriteLayerP;
- }
- }
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWAnimateSpriteWorld
- ///--------------------------------------------------------------------------------------
-
- SW_PASCAL void SWAnimateSpriteWorld(
- SpriteWorldPtr spriteWorldP)
- {
- register SpriteLayerPtr curSpriteLayerP;
- register SpritePtr curSpriteP;
- Rect rgnRect;
-
- // the current port should the one in which we are drawing
- SetPort(spriteWorldP->loadFrameP->framePort.monoGrafP);
-
- curSpriteLayerP = spriteWorldP->headSpriteLayerP;
-
- // iterate through the layers in this world
- while (curSpriteLayerP != NULL)
- {
- curSpriteP = curSpriteLayerP->headSpriteP;
-
- // iterate through the sprites in this layer
- while (curSpriteP != NULL)
- {
- if ((curSpriteP->needsToBeDrawn && curSpriteP->isVisible) ||
- (curSpriteP->needsToBeErased && !curSpriteP->isVisible))
- {
- // union last rect and current rect
- // this way is much faster than UnionRect
- curSpriteP->deltaFrameRect.top = (curSpriteP->oldFrameRect.top <
- curSpriteP->destFrameRect.top) ?
- curSpriteP->oldFrameRect.top :
- curSpriteP->destFrameRect.top;
- curSpriteP->deltaFrameRect.left = (curSpriteP->oldFrameRect.left <
- curSpriteP->destFrameRect.left) ?
- curSpriteP->oldFrameRect.left :
- curSpriteP->destFrameRect.left;
- curSpriteP->deltaFrameRect.bottom = (curSpriteP->oldFrameRect.bottom >
- curSpriteP->destFrameRect.bottom) ?
- curSpriteP->oldFrameRect.bottom :
- curSpriteP->destFrameRect.bottom;
- curSpriteP->deltaFrameRect.right = (curSpriteP->oldFrameRect.right >
- curSpriteP->destFrameRect.right) ?
- curSpriteP->oldFrameRect.right :
- curSpriteP->destFrameRect.right;
-
- // align the left edge to long word boundary
- curSpriteP->deltaFrameRect.left &=
- (spriteWorldP->loadFrameP->leftAlignFactor);
-
- // align the right edge to long word boundary
- if ((curSpriteP->deltaFrameRect.right &
- spriteWorldP->loadFrameP->rightAlignFactor) != 0)
- {
- curSpriteP->deltaFrameRect.right +=
- (spriteWorldP->loadFrameP->rightAlignFactor + 1) -
- (curSpriteP->deltaFrameRect.right &
- spriteWorldP->loadFrameP->rightAlignFactor);
- }
-
- // copy the back drop piece
- (*spriteWorldP->eraseDrawProc)(spriteWorldP->backFrameP,
- spriteWorldP->loadFrameP,
- &curSpriteP->deltaFrameRect,
- &curSpriteP->deltaFrameRect);
- }
-
- curSpriteP = curSpriteP->nextSpriteP;
- }
-
- curSpriteLayerP = curSpriteLayerP->nextSpriteLayerP;
- }
-
- curSpriteLayerP = spriteWorldP->headSpriteLayerP;
-
- // iterate through the layers in this world
- while (curSpriteLayerP != NULL)
- {
- curSpriteP = curSpriteLayerP->headSpriteP;
-
- // iterate through the sprites in this layer
- while (curSpriteP != NULL)
- {
- if (curSpriteP->isVisible)
- {
- if (curSpriteP->needsToBeDrawn)
- {
- if (curSpriteP->curFrameP->maskRgn != NULL)
- {
- rgnRect = (**curSpriteP->curFrameP->maskRgn).rgnBBox;
-
- // move the mask region to the new sprite location
- OffsetRgn(curSpriteP->curFrameP->maskRgn,
- (curSpriteP->destFrameRect.left - rgnRect.left) +
- curSpriteP->curFrameP->offsetPoint.h,
- (curSpriteP->destFrameRect.top - rgnRect.top) +
- curSpriteP->curFrameP->offsetPoint.v);
- }
-
- // copy the sprite image onto the back drop piece
- (*curSpriteP->frameDrawProc)(curSpriteP->curFrameP,
- spriteWorldP->loadFrameP,
- &curSpriteP->curFrameP->frameRect,
- &curSpriteP->destFrameRect);
- }
- else
- {
- SWUpdateSpriteOffscreen(spriteWorldP, curSpriteP);
- }
- }
-
- curSpriteP = curSpriteP->nextSpriteP;
- }
-
- curSpriteLayerP = curSpriteLayerP->nextSpriteLayerP;
- }
-
- // the current port should the one in which we are drawing
- SetPort(spriteWorldP->windowFrameP->framePort.monoGrafP);
-
- curSpriteLayerP = spriteWorldP->headSpriteLayerP;
-
- // iterate through the layers in this world
- while (curSpriteLayerP != NULL)
- {
- curSpriteP = curSpriteLayerP->headSpriteP;
-
- // iterate through the sprites in this layer
- while (curSpriteP != NULL)
- {
- if ((curSpriteP->needsToBeDrawn && curSpriteP->isVisible) ||
- (curSpriteP->needsToBeErased && !curSpriteP->isVisible))
- {
- // copy the backdrop+sprite piece from the loader to the screen
- (*spriteWorldP->screenDrawProc)(spriteWorldP->loadFrameP,
- spriteWorldP->windowFrameP,
- &curSpriteP->deltaFrameRect,
- &curSpriteP->deltaFrameRect,
- curSpriteP->screenMaskRgn);
-
- // set the delta and last rect to the current rect
- curSpriteP->deltaFrameRect = curSpriteP->destFrameRect;
- curSpriteP->oldFrameRect = curSpriteP->destFrameRect;
-
- // this sprite no longer needs to be drawn
- curSpriteP->needsToBeDrawn = false;
- curSpriteP->needsToBeErased = false;
- }
-
- curSpriteP = curSpriteP->nextSpriteP;
- }
-
- curSpriteLayerP = curSpriteLayerP->nextSpriteLayerP;
- }
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWUpdateSpriteOffscreen
- ///--------------------------------------------------------------------------------------
-
- static void SWUpdateSpriteOffscreen(
- SpriteWorldPtr spriteWorldP,
- register SpritePtr srcSpriteP)
- {
- Boolean needsRegionOffset = true;
- register SpriteLayerPtr curSpriteLayerP;
- register SpritePtr dstSpriteP;
- Rect rgnRect, srcSectRect, dstSectRect;
-
- curSpriteLayerP = spriteWorldP->headSpriteLayerP;
-
- // iterate through the layers in this world
- while (curSpriteLayerP != NULL)
- {
- dstSpriteP = curSpriteLayerP->headSpriteP;
-
- // iterate through the sprites in this layer
- while (dstSpriteP != NULL)
- {
- if ((dstSpriteP != srcSpriteP) &&
- ((dstSpriteP->needsToBeDrawn && dstSpriteP->isVisible) ||
- (dstSpriteP->needsToBeErased && !dstSpriteP->isVisible)))
- {
- // are the sprite’s rectangles overlapping?
- if (!((srcSpriteP->destFrameRect.top >= dstSpriteP->deltaFrameRect.bottom) ||
- (srcSpriteP->destFrameRect.bottom <= dstSpriteP->deltaFrameRect.top) ||
- (srcSpriteP->destFrameRect.left >= dstSpriteP->deltaFrameRect.right) ||
- (srcSpriteP->destFrameRect.right <= dstSpriteP->deltaFrameRect.left)))
- {
- if (needsRegionOffset && (srcSpriteP->curFrameP->maskRgn != NULL))
- {
- rgnRect = (**srcSpriteP->curFrameP->maskRgn).rgnBBox;
-
- // move the mask region to the new sprite location
- OffsetRgn(srcSpriteP->curFrameP->maskRgn,
- (srcSpriteP->destFrameRect.left - rgnRect.left) +
- srcSpriteP->curFrameP->offsetPoint.h,
- (srcSpriteP->destFrameRect.top - rgnRect.top) +
- srcSpriteP->curFrameP->offsetPoint.v);
-
- needsRegionOffset = false;
- }
-
- dstSectRect.left =
- (srcSpriteP->destFrameRect.left > dstSpriteP->deltaFrameRect.left)
- ? srcSpriteP->destFrameRect.left : dstSpriteP->deltaFrameRect.left;
-
- dstSectRect.top =
- (srcSpriteP->destFrameRect.top > dstSpriteP->deltaFrameRect.top)
- ? srcSpriteP->destFrameRect.top : dstSpriteP->deltaFrameRect.top;
-
- dstSectRect.right =
- (srcSpriteP->destFrameRect.right < dstSpriteP->deltaFrameRect.right)
- ? srcSpriteP->destFrameRect.right : dstSpriteP->deltaFrameRect.right;
-
- dstSectRect.bottom =
- (srcSpriteP->destFrameRect.bottom < dstSpriteP->deltaFrameRect.bottom)
- ? srcSpriteP->destFrameRect.bottom : dstSpriteP->deltaFrameRect.bottom;
-
- srcSectRect = dstSectRect;
-
- srcSectRect.left +=
- (srcSpriteP->curFrameP->frameRect.left - srcSpriteP->destFrameRect.left);
-
- srcSectRect.right +=
- (srcSpriteP->curFrameP->frameRect.left - srcSpriteP->destFrameRect.left);
-
- srcSectRect.top +=
- (srcSpriteP->curFrameP->frameRect.top - srcSpriteP->destFrameRect.top);
-
- srcSectRect.bottom +=
- (srcSpriteP->curFrameP->frameRect.top - srcSpriteP->destFrameRect.top);
-
- // copy a piece of the sprite image onto the back drop piece
- (*srcSpriteP->frameDrawProc)(srcSpriteP->curFrameP,
- spriteWorldP->loadFrameP,
- &srcSectRect,
- &dstSectRect);
- }
- }
-
- dstSpriteP = dstSpriteP->nextSpriteP;
- }
-
- curSpriteLayerP = curSpriteLayerP->nextSpriteLayerP;
- }
- }
-